﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;

//using Microsoft.VisualStudio.TestTools.UnitTesting;

//using Pibby.Core.Models;
//using Pibby.Core.Persistence;
//using Pibby.Core.Presenters;
//using Pibby.Core.PortableMedia;

//namespace Pibby.Core.Tests
//{
//    [TestClass]
//    //[TestCategory("Long Running")]
//    public class PortableMediaPresenterTests : IntegrationBaseTestFixture
//    {
//        private Stubs.PortableMediaStateView _view;
//        private PortableMediaModel _model;
//        private PortableMediaPresenter _presenter;
//        private Podcast _podcast;
//        private EpisodeCollection _episodes;

//        [TestInitialize]
//        public override void Setup()
//        {
//            base.Setup();

//            // create some podcasts and episodes...
//            Podcast p = Stubs.PodcastFactory.GeneratePodcasts ("mypodcast", 1)[0];

//            this._podcast = p;
//            this.Repository.Put(p);

//            this._episodes = Stubs.EpisodeFactory.GenerateEpisodes(p.SafeName, 5, EpisodeAge.BrandNew, EpisodeLifecycle.Downloaded);

//            foreach (var ep in this._episodes)
//            {
//                this.Repository.Put(ep);
//            }

//            this._view = new Stubs.PortableMediaStateView();
//            this._model = new PortableMediaModel(this.Repository, new Stubs.Folder("C:\\"));
//            this._presenter = new PortableMediaPresenter(this._view, this._model);
//        }

//        [TestCleanup]
//        public override void TearDown()
//        {
//            base.TearDown();

//            this._presenter.UnsubscribeToClientEvents();
//        }

//        [TestMethod]
//        public void WhenKnownDevice_PluggedIn_StatusIsChanged()
//        {
//            this._view.SimulateMediaSettingsChanged(true, "Known Device", "STONE PLUS", "Podcasts", OrganizationOption.Split, EjectOption.Auto, TransferOption.Auto);

//            this._view.SimulateDriveArrived("E:\\", "STONE PLUS");

//            Assert.IsTrue(this._view.RefreshDeviceCalled, "View should be updated when known device arrives");
//            Assert.IsTrue(this._view.DeviceConnected, "Device should be connected");
//            Assert.AreEqual("STONE PLUS", this._view.DeviceName, "Wrong device name");
//        }

//        [TestMethod]
//        public void WhenKnownDevice_PluggedIn_IgnoredIfSettingsDisabled()
//        {
//            this._view.SimulateMediaSettingsChanged(false, "Known Device", "STONE PLUS", "Podcasts", OrganizationOption.Split, EjectOption.Auto, TransferOption.Auto);

//            this._view.SimulateDriveArrived("E:\\", "STONE PLUS");

//            Assert.IsFalse(this._view.RefreshDeviceCalled, "View should not be updated when disabled known device arrives");
//            Assert.IsFalse(this._view.DeviceConnected, "Device should be ignored");
//        }

//        [TestMethod]
//        public void WhenKnownDevice_IsRemoved_StatusIsChanged()
//        {
//            this._view.SimulateMediaSettingsChanged(true, "Known Device", "STONE PLUS", "Podcasts", OrganizationOption.Split, EjectOption.Auto, TransferOption.Auto);

//            this._view.SimulateDriveRemoved("E:\\", "STONE PLUS");

//            Assert.IsTrue(this._view.RefreshDeviceCalled, "View should be updated when known device removed");
//            Assert.IsFalse(this._view.DeviceConnected, "Device should be disconnected");
//            Assert.AreEqual("STONE PLUS", this._view.DeviceName, "Wrong device name");
//        }

//        [TestMethod]
//        public void WhenUnknownDevice_Arrives_DoesNotChangeStatus()
//        {
//            this._view.SimulateMediaSettingsChanged(true, "Known Device", "STONE PLUS", "Podcasts", OrganizationOption.Split, EjectOption.Auto, TransferOption.Auto);

//            this._view.SimulateDriveArrived("Z:\\", "BOGUS");
//            Assert.IsFalse(this._view.RefreshDeviceCalled, "View should not be updated when unknown device arrives");
//            Assert.IsFalse(this._view.DeviceConnected, "Device should be disconnected");
			
//            this._view.SimulateDriveRemoved("Z:\\", "BOGUS");
//            Assert.IsFalse(this._view.RefreshDeviceCalled, "View should not be updated when unknown device removed");
//            Assert.IsFalse(this._view.DeviceConnected, "Device should be disconnected");
//        }

//        [TestMethod]
//        public void TransferContent_FileSpaceAvailable_TransfersAllFiles()
//        {
//            // simulate out of disk ????

//            this._view.SimulateMediaSettingsChanged(true, "Known Device", "STONE PLUS", "Podcasts", OrganizationOption.Split, EjectOption.Auto, TransferOption.Auto);
//            this._view.SimulateDriveArrived("E:\\", "STONE PLUS");

//            this._view.SimulateTransferContent(false);

//            Assert.AreEqual(5, this.Repository.CountEpisodes(EpisodeLifecycle.Downloaded));
//            Assert.AreEqual(5, this.Repository.GetAllEpisodes().Count);

//            //Assert.IsNotEmpty(this._model.TransferrableContent);

//            while (!this._view.TransferCompleteCalled)
//            {
//                System.Threading.Thread.Sleep(1000);
//            }

//            System.Threading.Thread.Sleep(1000);

//            Assert.AreEqual(this._episodes.Count, this._view.TotalItemsToTransfer);
//            Assert.AreEqual(this._episodes.Count, this._view.TotalItemsTransferred);

//            Assert.AreEqual(0, this.Repository.CountEpisodes(EpisodeLifecycle.Downloaded));
//            Assert.AreEqual(5, this.Repository.CountEpisodes(EpisodeLifecycle.Transferred));
//        }

//        [TestMethod]
//        public void TransferContent_FileSpaceAvailable_DeletesAfterCopy()
//        {
//            this._view.SimulateMediaSettingsChanged(true, "Known Device", "STONE PLUS", "Podcasts", OrganizationOption.Split, EjectOption.Auto, TransferOption.Auto);
//            this._view.SimulateDriveArrived("E:\\", "STONE PLUS");

//            this._view.SimulateTransferContent(true);

//            //Assert.IsNotEmpty(this._model.TransferrableContent);

//            while (!this._view.TransferCompleteCalled)
//            {
//                System.Threading.Thread.Sleep(1000);
//            }

//            System.Threading.Thread.Sleep(1000);

//            Assert.AreEqual(this._episodes.Count, this._view.TotalItemsToTransfer);
//            Assert.AreEqual(this._episodes.Count, this._view.TotalItemsTransferred);
//            Assert.AreEqual(0, this.Repository.CountEpisodes(EpisodeLifecycle.Downloaded));
//            Assert.AreEqual(5, this.Repository.CountEpisodes(EpisodeLifecycle.Transferred));
//        }

//        // no space for any

//        // space for some 

//        // auto eject

//        // auto update
//    }
//}
